package com.xhy.controller;


import com.xhy.entity.Video;
import com.xhy.service.IVideoService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 * 视频 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-08-30
 */
@RestController
@RequestMapping("/video")
public class VideoController {
    @Autowired
    private IVideoService videoService;
    @Autowired
    private RabbitTemplate rabbitTemplate;
    @PostMapping("/addVideo")
    public void addVideo(@RequestBody Video video){
        //1.保存video
        video.setCreatedAt(LocalDateTime.now());
        video.setUpdatedAt(LocalDateTime.now());
        videoService.save(video);
        //2.发出消息
        rabbitTemplate.convertAndSend("X","ES",video);
    }
}

